package com.CST.service.impl.zx;

import com.CST.common.api.ResultObject;
import com.CST.entity.zx.ZxDatadict;
import com.CST.mapper.cst.zx.ZxDatadictMapper;
import com.CST.service.zx.IZxDatadictService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ly
 * @since 2023-02-23
 */
@Service
public class ZxDatadictServiceImpl extends ServiceImpl<ZxDatadictMapper, ZxDatadict> implements IZxDatadictService {

    @Resource
    private ZxDatadictMapper zxDatadictMapper;
    //   分页查询数据字典的数据集合
    @Override
    public List<ZxDatadict> pageList(ZxDatadict zxDatadict) {
        return zxDatadictMapper.pageList(zxDatadict);
    }

//    判断zxDatadict的getDictCode是否重复
    @Override
    public ResultObject<String> addZxDatadict(ZxDatadict zxDatadict) {
        LambdaQueryWrapper<ZxDatadict> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(zxDatadict.getDictCode() != null,ZxDatadict::getDictCode,zxDatadict.getDictCode());
        List<ZxDatadict> list = this.list(lambdaQueryWrapper);
        if (list.size() > 0) {
            return ResultObject.failed("dictCode重复");
        }
        return this.save(zxDatadict)?ResultObject.success("新建成功"):ResultObject.failed("新建失败");
    }

    @Override
    public ResultObject<String> updateZxDatadict(ZxDatadict zxDatadict) {
        return this.updateById(zxDatadict)?ResultObject.success("更新成功"):ResultObject.failed("更新失败");
    }

//    逻辑删除
//    @Override
//    public ResultObject<String> deleteZxDatadicById(ZxDatadict zxDatadict) {
//        LambdaQueryWrapper<ZxDatadict> lambdaQueryWrapper = new LambdaQueryWrapper<>();
////        lambdaQueryWrapper.eq(ZxDatadict::getEnableFlag,0).eq(zxDatadict.get)
////        this.getOne()
////        return ;
//        return null;
//    }


}
